package com.twu.biblioteca.medias.book;

import com.twu.biblioteca.medias.Medias;
import com.twu.biblioteca.medias.CantUnlockAnUnlockedException;

/**
 * Created by mderaldo on 9/14/14.
 */
public class Book extends Medias {
    private String author;

    public Book(int code, String title, String author, int year) {
        this.code = code;
        this.title = title;
        this.author = author;
        this.year = year;
        this.locked = false;
    }

    public void unlock(){
        if(locked){
            locked = false;
        }else{
            throw new CantUnlockAnUnlockedException();
        }

    }

    @Override
    public String getDetails(){
        return "Cod: " + code + " | Title: "+ title + " | Author: " + author + " | Year Published: " + year;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Book)){
            return false;
        }
        if(this.code == ((Book)o).code){
            return true;
        }
        return false;
    }

}
